class OrdenServiciosController < ApplicationController
  # GET /orden_servicios
  # GET /orden_servicios.xml
  def index
    @orden_servicios = OrdenServicio.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @orden_servicios }
    end
  end

  # GET /orden_servicios/1
  # GET /orden_servicios/1.xml
  def show
    @orden_servicio = OrdenServicio.find(params[:id])
	@qr = "http://chart.apis.google.com/chart?chs=220x220&cht=qr&chl=http://localhost:3000/orden_servicios/" + @orden_servicio.id.to_s
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @orden_servicio }
    end
  end

  # GET /orden_servicios/new
  # GET /orden_servicios/new.xml
  def new
  	@direccions = Direccion.all(:conditions => {:cliente_id => session[:cliente_id]} )
    @orden_servicio = OrdenServicio.new
	@orden_servicio.paquetes.build
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @orden_servicio }
    end
  end

  # GET /orden_servicios/1/edit
  def edit
    @orden_servicio = OrdenServicio.find(params[:id])
  end

  # POST /orden_servicios
  # POST /orden_servicios.xml
  def create
    @orden_servicio = OrdenServicio.new(params[:orden_servicio])

    respond_to do |format|
      if @orden_servicio.save
        flash[:notice] = 'OrdenServicio was successfully created.'
        format.html { redirect_to(@orden_servicio) }
        format.xml  { render :xml => @orden_servicio, :status => :created, :location => @orden_servicio }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @orden_servicio.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /orden_servicios/1
  # PUT /orden_servicios/1.xml
  def update
    @orden_servicio = OrdenServicio.find(params[:id])

    respond_to do |format|
      if @orden_servicio.update_attributes(params[:orden_servicio])
        flash[:notice] = 'OrdenServicio was successfully updated.'
        format.html { redirect_to(@orden_servicio) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @orden_servicio.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /orden_servicios/1
  # DELETE /orden_servicios/1.xml
  def destroy
    @orden_servicio = OrdenServicio.find(params[:id])
    @orden_servicio.destroy

    respond_to do |format|
      format.html { redirect_to(orden_servicios_url) }
      format.xml  { head :ok }
    end
  end
end
